var YearReport = function() {
	return {
		datatable : null,
		init : function() {
			$("#startTime").datetimepicker({lang:'ch',timepicker:false, format:"Y"});
			this.initSearch();
			this.initListener();
		},
		initSearch : function() {
			if (!jQuery().dataTable) {
				return;
			}
			var yearReportListTable = $("#yearReportListTable").dataTable({
				"paging" : false,
				"sAjaxSource" : ctx + "/yearReport/search?now=" + new Date().getTime(),
				/* 使用post方式 */
				"fnServerData" : function(sSource, aoData, fnCallback) {
					var postData = {page : 1, start : 0, rows : 0, params : {}};
					if($('#userIds').val()){ 
						postData.params.userIds = $('#userIds').val();
						console.log($('#userIds').val());					
					}
					
					if($('#startTime').val()){
						postData.params.startTime = $('#startTime').val();
					}else{
						postData.params.startTime = "";
					}
					
					// 参数
					for (var i = 0, size = aoData.length; i < size; i++) {
						if (aoData[i].name == 'iDisplayLength') {
							postData.rows = aoData[i].value;
						} else if (aoData[i].name == 'iDisplayStart') {
							postData.start = aoData[i].value;
						} else if (aoData[i].name == 'sEcho') {
							postData.page = aoData[i].value;
						}
					}
					$.ajax({
						"dataType" : 'json',
						"cache": false,
						"type" : "POST",
						"url" : sSource,
						"data" : postData,
						"success" : function(data, textStatus, jqXHR){
							fnCallback(data.data, textStatus, jqXHR);
						}
					});
				},
				"bAutoWidth":false,
				"aoColumnDefs" : [
				{
					"data" : "index",
					"aTargets" : [ 0 ]
				},{
					"data" : "emplName",
					"aTargets" : [ 1 ],
				},{
					"data" : "emplCode",// 工号
					"aTargets" : [ 2 ],
				},{
					"data" : "groupName",// 部门
					"aTargets" : [ 3 ],
				},{
					"data" : "hoursTypeName",// 工时制名称
					"aTargets" : [ 4 ],
				},{
					"data" : "shouldAttHours",// 应出勤小时数
					"aTargets" : [ 5 ],
				},{
					"data" : "attHours",// 出勤小时
					"aTargets" : [ 6 ],
				},{
					"data" : "attDays",// 出勤天数
					"aTargets" : [ 7 ],
				},{
					"data" : "averageDayHours",// 日平均工时
					"aTargets" : [ 8 ],
				},{
					"data" : "absentHours",// 旷工时长
					"aTargets" : [ 9 ],
				},{
					"data" : "overTimeHours", // 加班时长
					"aTargets" : [ 10 ],
				},{
					"data" : "holidayOvertimeHours", // 法定节假日加班时长
					"aTargets" : [ 11 ],
				},{
					"data" : "riteLeaveHours", // 喜丧假
					"aTargets" : [ 12 ],
				},{
					"data" : "sickLeaveHours", // 病假
					"aTargets" : [ 13 ],
				},{
					"data" : "affairsLeaveHours", // 事假
					"aTargets" : [ 14 ],
				},{
					"data" : "yearLeaveHours", // 年休假
					"aTargets" : [ 15 ],
				},{
					"data" : "paidLeaveHours", // 调休
					"aTargets" : [ 16 ],
				},{
					"data" : "inductrialInjuryHours", // 工伤
					"aTargets" : [ 17 ],
				}]
			});
			this.datatable = yearReportListTable;
		},reSearch:function(){
        	this.datatable.fnDraw();
        },initListener:function(){
			/**
			 * 监听开关事件
			 */
        	/*
        	 * 选择员工modal
        	 */
        	jQuery("#selected").click(function(){
        		$("#groupUserModal").modal('show');
        	});
        	/*
        	 * 查询
        	 */
        	jQuery("#searchBtn").click(function() { 
        		YearReport.reSearch();
				return false;
			});
     	}
	}
}();